<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\News\News;
use App\Models\News\NewsArtist;
use App\Models\News\NewsAuction;
use App\Models\News\NewsContent;
use App\Models\News\NewsOrganization;
use App\Models\Artists\ArtistsClass;
use App\Models\Artists\Artist;
use App\Models\Artists\Apply;
use App\Models\Artists\JoinArtist;
use App\Models\Artists\ArtistsDomain;
use App\Models\Artists\ArtistsArea;
use App\Models\Artists\ArtistsVist;
use App\Models\Artists\ArtistsArt;
use App\Models\Artists\ArtistsSeal;
use App\Models\Artists\ArtistsPublication;
use App\Models\Artists\ArtistsUserClass;
use App\Models\Artists\ArtistsPhoto;
use App\Models\Artists\NewsArtists;
use App\Models\Artists\ArtistsUserNewsClass;
use App\Models\Artists\Message;
use App\Models\UsersAttr;
use App\Models\Area;
use App\Models\Auctions\Company;
use App\Models\Auctions\CompanyArea;
use App\User;
use App\Models\PositionList;
use Illuminate\Support\Facades\Storage;

use App\Models\Exhibition\Exhibition;
use App\Helper\Build\Build as Builds;
class Synchro extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'synchro';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
		// return $this->Exhibition();
        //
		/*$this->apply();
		*/
		return file_get_contents('http://web.ahxmgk.com/activity/app/index.php?i=31&c=entry&rid=56&do=updatecout&m=dg_dati');
		// for($i=1;$i<137;$i++)
		// {
		// 	$this->artist1($i);
		// }
		
		//return $ret;
    }

    public function artistthumb()
    {
    	$variable = Artist::where('thumb', 'like', '../upload')->get();
    	foreach ($variable as $key => $value) {
    		# code...
    		$file = str_replace('../upload', 'http://img.zhuokearts.com/upload.v1', $value->thumb);
    		$file = str_replace('\\', '/', $file);
    		if(file_exists($file))
    		{

    		}
    		$value->thumb;
    	}
    }
	
	public function Exhibition()
	{
		$Builds = new Builds();
		for($i=1;$i<4;$i++)
		{
	    	foreach (Exhibition::where('id','>',3277)->get()->forPage($i,5000)  as $key => $value) {
	    		# code...
				if(!$value)break;
	    		var_export($Builds->zl($value));
	    		echo $value->id;
	    	}
    	}
		// foreach(Exhibition::all() as $row)
		// {
			// $Builds->zl($row);
		// }
		dd(1);
	}
	
	

    public function replacenews()
    {
    	foreach (PositionList::all()  as $key => $value) 
    	{


    		$thumb = getFieldValue($value->content, 'thumb');

    		if(isset($value->content['thumb']) && !empty($value->content['thumb']) && !strstr($value->content['thumb'], 'http'))
    		{
    			// dd('http://oss.img.zhuokearts.com/titlepic/'.$value->content['thumb']);
    			$arr = $value->content;
    			$arr['thumb'] = 'http://oss.img.zhuokearts.com/titlepic/'.$value->content['thumb'];
    			$value->content = $arr;
				// $value->content['thumb'] = 'http://oss.img.zhuokearts.com/titlepic/'.$value->content['thumb'];
    			$value->save();
    			echo $value->id;
    		}

    		
    		 
    	}
    }
    protected function aaa($field, $arr)
    {
    	if(array_key_exists($field, $arr))
		{
			//如果是图片，则加上url
			if(strstr($field, 'thumb')){
				return thumbTitlepicUrl($arr[$field]);
			}
			return $arr[$field];
		}else{
			return '';
		}
    }

    public function replaceDomain()
    {
    	for($i=1;$i<51;$i++)
		{
	    	foreach (ArtistsArt::all()->forPage($i,1000)  as $key => $value) {
	    		# code...
	    		$value->thumb = str_replace('http://3gimg.zhuokearts.com/Image', 'http://3gimg.zhuokearts.com/image', $value->thumb);
	    		// $value->banner = str_replace('http://3gimg.zhuokearts.com/Image', 'http://3gimg.zhuokearts.com/image', $value->banner);
	    		$value->save();
	    		echo $value->id;
	    	}
    	}
    }

    public function upload_ali()
    {
    	$upload = Storage::disk('upload');dd(Storage::disk('oss')->exists('./titlepic/images/8b2f15f556a0fbc5c66940f9df9b5112.jpg'));
    	foreach ($upload->allFiles('./titlepic/images/20181019') as $key => $value) {
    		# code...
    		// if(strstr($value, 'skin') || strstr($value, 'jack'))continue;
			if(Storage::disk('oss')->exists($value))continue;
    		(Storage::disk('oss')->put($value, $upload->get($value)));
    		echo $value.chr(10);
    	};
    }

    public function updateclassid()
    {
    	foreach(NewsArtists::get() as $row)
    	{
    		$info = News::find($row->new_id);
    		if($info){
    			$row->class_id = $info->class_id;
    			$row->save();
    		}
    		echo $row->id;
    	}
    }


    public function class_city($page)
    {
        $client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/class_city?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		$temp = [];
		foreach($ret->data as $k=>$row)
		{
			$temp[] = [
				'id' => $row->id,
				'name' => $row->title,
				'listorder' => $row->xuhao,
				'parent_id' => 0
			];
		}
		echo 'content-'.count($artist).chr(10);
		
		CompanyArea::insert($temp);
		sleep(1);
    }


    public function company($page)
    {
    	$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/company?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		$temp = [];
		foreach($ret->data as $k=>$row)
		{
			$temp = [
				'id' => $row->id,
				'title' => $row->title,
				'ftitle' => $row->title2,
				'listorder' => $row->xuhao,
				'status' => $row->cnflag,
				'content' => $row->content,
				'onclick' => $row->viewcount,
				'tjflag' => $row->tjflag,
				'thumb' => $row->picfilename,
				'logo' => $row->logo,
				'banner' => $row->banner,
				'contact_name' => $row->linkman,
				'tel' => $row->tel,
				'fax' => $row->fax,
				'email' => $row->email,
				'websiteurl' => $row->websiteurl,
				'address' => $row->address,
				'city_id' => $row->city_id,
				'zhengpai' => $row->zhengpai,
				'pagebottominfo' => $row->pagebottominfo,
				'gy' => $row->gy,
				'db' => $row->db,
				'auction_domain' => $row->auction_domain,
				'auction_weixin' => $row->auction_weixin,
				'auction_weibo' => $row->auction_weibo,
				'firstchar' => $row->PY,
				'is_user_apply' => $row->IS_USER_APPLY,
			];
			if(!Company::find($row->id))Company::insert($temp);
		}
		echo 'content-'.count($artist).chr(10);
		
		// Company::insert($temp);
		sleep(1);
    }

    public function areas($page)
    {
    	$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/areas?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		$temp = [];
		foreach($ret->data as $k=>$row)
		{
			$temp[] = [
				'id' => $row->Area_ID,
				'name' => $row->Area_Name,
				'listorder' => $row->Area_Order,
				'layer' => $row->Area_Layer,
				'parent_id' => $row->Area_FatherID
			];
		}
		echo 'content-'.count($artist).chr(10);
		
		Area::insert($temp);
		sleep(1);
    }
	
	public function message($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/message?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$artists_id = $row->artist_id;
			$item_type = 'artist';
			if($artists_id == 0)
			{
				$artists_id = $row->arts_id;
				$item_type = 'arts';
			}
			$c = substr($row->creatDate,0,19);
			if($c == '1900-01-01 00:00:00' || empty($c) || $c<'1990-01-01 00:00:00')
			{
				$c = null;
			}
			$attr = [
				'id' => $row->id,
				'user_login' => $row->usercode,
				'ip_address' => $row->IPaddress,
				'item_id' => $artists_id,
				'item_type' => $item_type,
				'content' => $row->Content,
				'remark' => $row->ReContent,
				'created_at' => $c,
				'status' => $row->verifystatus,
				
			];
			Message::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	
	public function user_news_class($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/newsuserclass?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$attr = [
				'id' => $row->id,
				'user_id' => $row->user_id,
				'name' => $row->name,
				'parent_id' => (int)$row->pid
			];
			ArtistsUserNewsClass::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	public function photo($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/photo?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$c = substr($row->creatDate,0,19);
			if($c == '1900-01-01 00:00:00' || empty($c) || $c<'1990-01-01 00:00:00')
			{
				$c = null;
			}
			$attr = [
				'artists_id' => $row->ID_ZK,
				'listorder' => $row->XuHao,
				'status' => (int)$row->cnFlag,
				'title' => $row->title,
				'thumb' => $row->picFileName,
				'artists_class_id' => (int)$row->photo_classid,
				'created_at' => $c,
			];
			ArtistsPhoto::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	public function arts_user_class($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/arts_user_class?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			if(!ArtistsUserClass::find($row->ID))
			{
				$attr = [
					'id' => $row->ID,
					'user_id' => $row->UID,
					'listorder' => $row->SORTID,
					'class_type' => $row->CLASS_TYPE,
					'name' => $row->NAME,
					'parent_id' => (int)$row->PARENT_ID
				];
				ArtistsUserClass::insert($attr);
			}
			
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	
	public function publications($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/publications?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$c = substr($row->creatDate,0,19);
			if($c == '1900-01-01 00:00:00' || empty($c) || $c<'1990-01-01 00:00:00')
			{
				$c = null;
			}
			$p = substr($row->pubdata,0,19);
			if($p == '1900-01-01 00:00:00' || empty($p) || $p<'1990-01-01 00:00:00')
			{
				$p = null;
			}
			
			$attr = [
				'listorder' => $row->XuHao,
				'artists_id' => $row->id_zk,
				'artists_class_id' => $row->artist_class_id,
				'user_id' => $row->user_id,
				'status' => (int)$row->cnFlag,
				'title' => $row->title,
				'thumb' => $row->picFileName,
				'onclick' => $row->viewcount,
				'content' => $row->content,
				'attr' => json_encode([
					'press' => $row->press,
					'author' => $row->author,
					'editor' => $row->editor,
					'format' => $row->format,
					'pricing' => $row->pricing,
					'isbn' => $row->isbn,
					'impressions' => $row->impressions
				]),
				'created_at' => $c,
				'pubdate_at' => $p,
			];
			ArtistsPublication::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	
	public function seal($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/seal?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$c = substr($row->creatDate,0,19);
			if($c == '1900-01-01 00:00:00' || empty($c) || $c<'1990-01-01 00:00:00')
			{
				$c = null;
			}
			
			$attr = [
				'listorder' => $row->xuHao,
				'artists_id' => $row->artist_id_zk,
				'status' => (int)$row->cnFlag,
				'title' => $row->title,
				'thumb' => $row->picFileName,
				'onclick' => $row->viewcount,
				'created_at' => $c,
			];
			ArtistsSeal::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	
	public function arts($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/arts?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$c = substr($row->creatDate,0,19);
			if($c == '1900-01-01 00:00:00' || empty($c) || $c<'1990-01-01 00:00:00')
			{
				$c = null;
			}
			$e = substr($row->updatedate,0,19);
			if($e == '1900-01-01 00:00:00' || empty($e) || $e<'1990-01-01 00:00:00')
			{
				$e = null;
			}
			$attr = [
				'id' => $row->id,
				'status'=>$row->cnFlag,
				'listorder' => $row->XuHao,
				'artists_id' => $row->id_zk,
				'artists_class_id' => (int)$row->artist_class_id,
				'artists_sys_class_id' => (int)$row->ArtsSysClass,
				'auction_art_id' => (int)$row->AUCTIONART_ID,
				'user_id' => $row->user_id,
				'title' => $row->title,
				'thumb' => $row->picFileName,
				'onclick' => $row->viewcount,
				'content' => $row->content,
				'is_recommed' => $row->isRun,
				'attr' => json_encode([
					'spec' => $row->spec,
					'size' => $row->size,
					'nd' => $row->nd,
				]),
				'created_at' => $c,
				'updated_at' => $e,
			];
			if(!ArtistsArt::find($row->id))ArtistsArt::insert($attr);
		}
		// dd($attr);
		echo $page;
		
		//dd($page);
		sleep(1);
	}
	
	public function vist($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/vist?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$attr[] = [
				'artists_id' => $row->artist_id,
				'user_id' => $row->vis_user_id,
				'created_at' => substr($row->sysdate,0,19),
			];
		}
		// dd($attr);
		ArtistsVist::insert($attr);
		//dd($page);
		sleep(1);
	}


    public function users($page)
    {
    	$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/user?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		$attr = $artist = [];
		foreach($ret->data as $k=>$row)
		{
			$artist[$k] = [
				'id' => $row->UserID,
				'name' => $row->LoginID,
				'password' => bcrypt($row->SrcPwd),
				'mobile' => $row->Mobile,
				'group_id' => $row->Membership,
				'login_count' => $row->LoginCount,
				'last_login_time' => $row->LastTime,
				'last_login_ip' => $row->LastIP,
				'register_ip' => $row->RegIP,
				'integral' => $row->Integral,
				'avatar' => $row->Image,
				'nickname' => $row->NickName,
				'realname' => $row->Name,
				'sex' => $row->Sex,
				'email' => $row->EMail,
				'liveness_cnt' => $row->LivenessCnt,
				'created_at' => $row->InsertTime,
			];
			$attr[$k] = [
				'user_id' => $row->UserID,
				'zip' => $row->Zip,
				'card_no' => $row->CardNo,
				'card_images' => $row->CardImages,
				'bank_no' => $row->BankNo,
				'bankde_posit' => $row->Bankdeposit,
				'created_at' => $row->InsertTime,
				// 'birthday' => str_replace(' 00:00:00', '', $row->Birthday),
				'area' => $row->Area,
				'address' => $row->Address,
			];
			if($row->Birthday)
			{
				$attr[$k]['birthday'] = str_replace(' 00:00:00', '', $row->Birthday);
			}else{
				$attr[$k]['birthday'] = null;
			}
			//dd($attr);
			
		}

		echo 'content-'.count($artist).chr(10);
		User::insert($artist);
		UsersAttr::insert($attr);
		//dd($page);
		sleep(1);
    }
	
	public function apply($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/apply?page='.$page);
		$ret = json_decode($res->getBody());
		
		if(empty($ret->data))return;
		foreach($ret->data as $row)
		{
			$temp = $this->explodes($row->picFileName,'trim');
			if($temp)
				$temp = json_encode($temp);
			else
				$temp = '';
			$artist[] = [
				'id' => $row->id,
				'name' => $row->artist_name,
				'class_id' => $row->class_id,
				'user_id' => $row->UID,
				'city_id' => $row->city_id,
				'mobile' => $row->tel,
				'content' => $row->content,
				'created_at' => $row->creatDate,
				'iplong' => ip2long($row->ipaddress),
				'avatar' => $row->avatar,
				'status' => $row->state,
				'thumbs' => $temp,
			];
			
		}
		echo 'content-'.count($artist).chr(10);
		Apply::insert($artist);
		sleep(1);
	}
	
	public function artist($page = 1)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/artist?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		foreach($ret->data as $k=>$row)
		{
			$temp = $this->explodes($row->classs,'intval');
			if($temp)
				$temp = json_encode($temp);
			else
				$temp = '';
			$artist[$k] = [
				'id' => $row->id,
				'artists_id' => $row->id_zk,
				'user_id' => $row->user_id,
				'name' => $row->title,
				'class_id' => $row->class_id,
				'class_ids' => $temp,
				'city_id' => $row->city_id,
				'onclick' => $row->viewcount,
				// 'end_time' => $row->ExpiredDate,
				'start_time' => $row->jmDate,
				'content' => $row->content,
				'level' => $row->tjv1,
				'avatar' => $row->picFileName,
				'banner' => $row->picFileName1,
				'firstchar' => $row->initial,
				// 'is_mingjia' => $row->isMingJia,
				'service_user_id' => $row->Service_id,
				// 'is_join' => $row->redflag,
				'status' => $row->echoFlag,
				// 'created_at' => $row->creatdate,
				// 'created_at' => $row->creatDate,
				// 'updated_at' => $row->editdate,
				
			];
			if($row->ExpiredDate && !strstr($row->ExpiredDate, '.000'))$artist[$k]['end_time'] = $row->ExpiredDate;
			if($row->creatDate)$artist[$k]['created_at'] = $row->creatDate;
			var_export(JoinArtist::insert($artist[$k]));
		}
		echo 'content-'.count($artist).chr(10);
		
		//JoinArtist::insert($artist);
		sleep(1);
	}
	
	public function artist1($page = 1)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://zhuokearts.iok.la:8888/artist?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		foreach($ret->data as $k=>$row)
		{
			$info = Artist::find($row->id);
			if($info)
			{
				$info->avatar = $row->picfilename;
				$info->content = $row->content;
				$info->content2 = $row->content2;
				$info->content3 = $row->content3;
				$info->save();
				
			}
			
			/*
			$e = substr($row->userdate,0,19);
			if($e == '1900-01-01 00:00:00' || empty($e) || $e<'1990-01-01 00:00:00')
			{
				$e = null;
			}
			$artist[$k] = [
				'id' => $row->id,
				
				'firstchar' => $row->initial,
				'name' => $row->title,
				// 'is_mingjia' => $row->isMingJia,
				// 'service_user_id' => $row->Service_id,
				// 'is_join' => $row->redflag,
				'status' => $row->enflag,
				'created_at' => $e,
				// 'created_at' => $row->creatDate,
				'updated_at' => $e,
				
			];*/
			// var_export(Artist::insert($artist[$k]));
		}
		echo 'content-'.$row->id.chr(10);
		
		//JoinArtist::insert($artist);
		sleep(1);
	}
	
	protected function domain($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/domain?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		$temp = [];
		foreach($ret->data as $k=>$row)
		{
			$temp[] = [
				'id' => $row->ID,
				'user_id' => $row->UID,
				'artists_id' => $row->PROJECT_WEB_ID,
				'value' => $row->DOMAIN_PREFIX,
				'created_at' => $row->CREATED,
			];
		}
		echo 'content-'.count($artist).chr(10);
		
		ArtistsDomain::insert($temp);
		sleep(1);
	}
	protected function area($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/area?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		$temp = [];
		foreach($ret->data as $k=>$row)
		{
			$temp[] = [
				'id' => $row->id,
				'name' => $row->title,
				'listorder' => $row->XuHao
			];
		}
		echo 'content-'.count($artist).chr(10);
		
		ArtistsArea::insert($temp);
		sleep(1);
	}
	
	protected function getNewsLaster($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/news?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		
		foreach($ret->data as $row)
		{
			if(empty($row->id))continue;
			$news = [
				'title'=> $row->title,
				'created_at'=> $row->creatDate,
				'class_id'=> $row->Class_id,
				'ftitle'=> $row->title,
				'index_title'=> $row->title,
				'source'=> $row->staple,
				'author'=> $row->editor,
				'status'=> $row->chkflag,
				'onclick'=> $row->viewcount,
				'pl_count'=> $row->pCount,
				// 'id'=> $row->id,
			];
			$news_id = News::insertGetId($news);
			$artists = $this->explodes($row->artist_id);
			if($artists)
			{
				foreach($artists as $r)
				{
					$artist[$news_id.$r] = [
						'new_id' => $news_id,
						'artist_id' => $r,
					];
				}
				
			}
			if($row->corp_id>0)
			{
				$auction[] = [
					'new_id' => $news_id,
					'auction_id' => $row->corp_id,
				];
			}
			
			if($row->ysjg_id>0)
			{
				$org[] = [
					'new_id' => $news_id,
					'org_id' => $row->ysjg_id,
				];
			}
			
			$content[] = [
				'new_id' => $news_id,
				'content' => $row->content,
			];
			
			
			
		}
		//News::insert($news);
		//echo 'news-'.count($news).chr(10);
		//sleep(1);
		NewsContent::insert($content);
		echo 'content-'.count($content).chr(10);
		sleep(1);
		if($artist)NewsArtist::insert($artist);
		echo 'artist-'.count($artist).chr(10);
		sleep(1);
		if($auction)NewsAuction::insert($auction);
		echo 'auction-'.count($auction).chr(10);
		sleep(1);
		if($org)NewsOrganization::insert($org);
		echo 'org-'.count($org).chr(10);
		echo 'page='.$page.chr(10).chr(10).chr(10);
		unset($news, $content, $artist, $auction, $org);
		return $ret;
	}
	
	protected function getNews($page)
	{
		$client = new \GuzzleHttp\Client();
		$res = $client->request('GET', 'http://apitest.zhoukearts.com/news?page='.$page);
		$ret = json_decode($res->getBody());
		$news = $artist = $org = $content = $auction = [];
		if(empty($ret->data))return;
		
		foreach($ret->data as $row)
		{
			if(empty($row->id))continue;
			$news[] = [
				'title'=> $row->title,
				'created_at'=> $row->creatDate,
				'class_id'=> $row->Class_id,
				'ftitle'=> $row->title,
				'index_title'=> $row->title,
				'source'=> $row->staple,
				'author'=> $row->editor,
				'status'=> $row->chkflag,
				'onclick'=> $row->viewcount,
				'pl_count'=> $row->pCount,
				'id'=> $row->id,
			];
			
			$artists = $this->explodes($row->artist_id);
			if($artists)
			{
				foreach($artists as $r)
				{
					$artist[$row->id.$r] = [
						'new_id' => $row->id,
						'artist_id' => $r,
					];
				}
				
			}
			if($row->corp_id>0)
			{
				$auction[] = [
					'new_id' => $row->id,
					'auction_id' => $row->corp_id,
				];
			}
			
			if($row->ysjg_id>0)
			{
				$org[] = [
					'new_id' => $row->id,
					'org_id' => $row->ysjg_id,
				];
			}
			
			$content[] = [
				'new_id' => $row->id,
				'content' => $row->content,
			];
			
			
			
		}
		News::insert($news);
		echo 'news-'.count($news).chr(10);
		sleep(1);
		NewsContent::insert($content);
		echo 'content-'.count($content).chr(10);
		sleep(1);
		if($artist)NewsArtist::insert($artist);
		echo 'artist-'.count($artist).chr(10);
		sleep(1);
		if($auction)NewsAuction::insert($auction);
		echo 'auction-'.count($auction).chr(10);
		sleep(1);
		if($org)NewsOrganization::insert($org);
		echo 'org-'.count($org).chr(10);
		echo 'page='.$page.chr(10).chr(10).chr(10);
		unset($news, $content, $artist, $auction, $org);
		return $ret;
	}
	
	
	public function explodes($string, $fun= 'intval')
	{
		if(empty($string) || $string == '')return false;
		$arr = [];
		if(strstr($string, ','))
		{
			$arr = explode(',', $string);
			foreach($arr as $k=>$row)
			{
				if(empty($row))
				{
					unset($arr[$k]);
					continue;
				}
				$arr[$k] = $fun($row);
			}
			return $arr;
			
		}else{
			return [$string];
		}
	}
	
}
